<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="郭嘉碧">
    <title></title>
    <style>
     *{
        box-sizing: border-box;
    }
    ul{
        padding: 0;
        margin: 0;
        list-style: none;
    }
    .box{
        width: 1226px;
        height: 460px; 
        margin: 100px auto;
        position: relative;
    }
    .img-list li{
        position: absolute;
        top: 0;
        left: 0;
        display: none;
    }
    .img-list li.current{
        display: block;
    }
    .indicator{
        width: 100%;
        position: absolute;
        left: 0;
        bottom: 20px;
        display: flex;
        justify-content: center;
        margin-left: 500px;
    }
    .indicator li{
        width: 10px;
        height: 10px;
        background-color: #8E8881;
        text-align: center;
        line-height: 20px;
        margin: 0 5px;
        border-radius: 50%;
        cursor: pointer;
        right: 0;
    }
    .indicator li.active{
        background-color: white;
    }
    .img-click span{
        display: inline-block;
        width: 30px;
        height: 63px;
        line-height: 40px;
        text-align: center;
        color: white;
        background-color: rgba(0, 0, 0, 0.1);
        position: absolute;
        top: calc(50% - 25px);
        display: none;
    }
    .img-click span:hover{
        background-color: orange;
        cursor: pointer;
    }
    .img-click .prev{
        background-image: url('img/icon-slides.png');
        background-position: 83px 68px;
        left: 0;
    }
    .img-click .next{
        background-image: url('img/icon-slides.png');
        background-position: 130px 68px;
        right: 0;
    }
    
    </style>
</head>
<body>
    <div class="box">
        <ul class="img-list">
            <li class="current"><a href="#"><img src="img/01.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/02.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/03.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/04.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/05.jpg" alt=""></a></li>
        </ul>
        <ul class="indicator">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <div class="img-click">
            <span class="prev"></span>
            <span class="next"></span>
        </div>
    </div>

    <script src="./jquery.js"></script>
</body>
</html>
<script>
    var index = 0;

    var timer = setInterval(nextImg,1000);
    function nextImg(){
        index ++;
        if (index == 5) {
            index = 0;
        }
        showImg();
    }
    function showImg(){
        $('.img-list li').eq(index).stop().fadeIn(300).siblings().stop().fadeOut(300);
        $('.indicator li').eq(index).addClass('active').siblings().removeClass('active');
    }

    $('.box').mouseenter(function(){
        clearInterval(timer);
        $('.img-click span').show();
    }).mouseleave(function(){
        timer = setInterval(nextImg,1000);
        $('.img-click span').hide();
    });
    // 根据指示灯切换
    $('.indicator li').click(function(){
        index = $(this).index();
        showImg();
    });

    //  点击切换
    $('.next').click(function(){
        nextImg();
    });
    $('.prev').click(function(){
        index --;
        if (index == -1) {
            index = 4;
        }
        showImg(); 
    });


</script>